﻿using AutoMapper;
using MediatR;
using S.Archives.Domain.S.ArchivesDto;
using S.Archives.Infrstructre.InterFace;
using S.Archives.Read.Api.Application.Command;

namespace S.Archives.Read.Api.Application.CommandHandlers
{
    public class SelMaleEmaleSelQCCommandHandler : IRequestHandler<SelMaleEmaleSelQCCommand, List<EnumStringDto>>
    {
        private readonly ISheepFileRepository sheepFileRepository;
        private readonly IMapper mapper;
        public SelMaleEmaleSelQCCommandHandler(ISheepFileRepository sheepFileRepository, IMapper mapper)
        {
            this.sheepFileRepository = sheepFileRepository;
            this.mapper = mapper;
        }
        /// <summary>
        /// 根据类型查询下拉框(未入场)
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>

        public async Task<List<EnumStringDto>> Handle(SelMaleEmaleSelQCCommand request, CancellationToken cancellationToken)
        {
            var list = sheepFileRepository.GetAllAsync().Result;
            if (request.FileType > 0)
            {
                list = list.Where(x => x.FileType == request.FileType).ToList();
            }
            list=list.Where(x=>x.PresenceState==1).ToList();



            List<EnumStringDto> enumDto = new List<EnumStringDto>();
            enumDto = mapper.Map<List<EnumStringDto>>(list);
            return  enumDto;
        }
    }
}
